<?php // This is the main page for the admin site.
require_once('./inc/inc.common.php');
$tmpl 		= new mvTemplate();
$tmpl->page_title('Statistics');

if(!isset($_SESSION['user']) || !$_SESSION['user']->isAdmin){
	mvError::userError('Not Authorized', 'You are not authorized to view that page.');
	header('location: index.php');
	die();
}

$sql = "SELECT
			SUM(Approved = 'Y' AND  ParentID = 0) as articley,
			SUM(Approved = 'N' AND ParentID = 0) as articlen,
			SUM(Approved IN ('Y','N') AND ParentID = 0) as articlea,
			SUM(Approved = 'Y' AND  ParentID != 0) as commenty,
			SUM(Approved = 'N' AND ParentID != 0) as commentn,
			SUM(Approved IN ('Y','N') AND ParentID != 0) as commenta,
			SUM(Approved = 'Q') as qy,
			SUM(Approved = 'A') as qn,
			SUM(Approved IN ('Q','A')) as qa
 		FROM articles";
$query = $GLOBALS['db']->prepare_execute($sql);
$data = $query->fetch();

$tmpl->assign('approvedarticles', $data['articley']);
$tmpl->assign('pendingarticles', $data['articlen']);
$tmpl->assign('totalarticles', $data['articlea']);
$tmpl->assign('approvedcomments', $data['commenty']);
$tmpl->assign('pendingcomments', $data['commentn']);
$tmpl->assign('totalcomments', $data['commenta']);
$tmpl->assign('pendingquestions', $data['qy']);
$tmpl->assign('respondedquestions', $data['qn']);
$tmpl->assign('totalquestions', $data['qa']);

$tmpl->page_display('a_index.tpl');
?>